<?php

namespace Kateba\SiteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class SiteController extends Controller {
    
    public function contactUsAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(7);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:contact.html.twig', array('page' => $page));
    }
    
    public function servicesAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(8);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:services.html.twig', array('page' => $page));
    }

    public function aboutAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(2);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:about.html.twig', array('page' => $page));
    }

    public function iproAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(2);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:ipro.html.twig', array('page' => $page));
    }

    public function isoAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(3);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:iso.html.twig', array('page' => $page));
    }

    public function eoAction() {
        $page = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Page')->find(4);
        if (!$page) {
            throw $this->createNotFoundException('Can not find the requested page');
        }
        return $this->render('KatebaSiteBundle:Site:eo.html.twig', array('page' => $page));
    }

    public function renderSliderImagesAction() {
        $entities = $this->getDoctrine()->getEntityManager()->getRepository('KatebaSiteBundle:Slider')->findAll();
        return $this->render('KatebaSiteBundle:Site:sliderImages.html.twig', array(
                    'entities' => $entities
                ));
    }

    public function galleryAction($page = 1) {
        //the results per page number
        $itemsPerPage = 6;
        //get the table data
        $data = $this->getDoctrine()->getRepository('KatebaSiteBundle:GalleryImage')->getGalleryImages($page, $itemsPerPage);
        //get the objects
        $entities = $data['entities'];
        //get the count of total results
        $count = $data['count'];
        //calculate the last page number
        $lastPageNumber = (int) ($count / $itemsPerPage);
        if (($count % $itemsPerPage) > 0) {
            $lastPageNumber++;
        }
        return $this->render('KatebaSiteBundle:GalleryImage:index.html.twig', array(
                    'entities' => $entities,
                    'count' => $count,
                    'page' => $page,
                    'lastPageNumber' => $lastPageNumber
                ));
    }

}
